package cn.edu.hpu.action;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.hpu.pojo.Usergroup;
import cn.edu.hpu.service.UsergroupService;
import cn.edu.hpu.util.TimeUtil;

import com.opensymphony.xwork2.ActionSupport;


public class UsergroupAction extends ActionSupport{
 static final long serialVersionUID = 1L;
	private UsergroupService usergroupService;
	private List<Usergroup> uglist;
	private Usergroup usergroup;
	private String id;
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	public String findAllUsergroup(){
		try {
			uglist = usergroupService.findAllUsergroups();
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
		
	}
	public String saveUsergroup(){
		Usergroup ug = new Usergroup();
		ug.setCreatetime(TimeUtil.getTime());
		ug.setGroupname(usergroup.getGroupname());
		usergroupService.saveUsergroup(ug);
		return SUCCESS;
	}
	
	public String deleteusergroup(){
		usergroupService.delete(id);
		return SUCCESS;
	}
	public String updateUsergroup(){
		usergroupService.updateusergroup(usergroup);
		return SUCCESS;
	}
	public String edit(){
		usergroup = usergroupService.findA(id);
		return SUCCESS;
	}
	
	
	//setter,getter
	
	@Autowired
	public void setUsergroupService(UsergroupService usergroupService) {
		this.usergroupService = usergroupService;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public Usergroup getUsergroup() {
		return usergroup;
	}
	public void setUsergroup(Usergroup usergroup) {
		this.usergroup = usergroup;
	}
	public List<Usergroup> getUglist() {
		return uglist;
	}
	public void setUglist(List<Usergroup> uglist) {
		this.uglist = uglist;
	}
}
